<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>- 作品编辑</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/plugins/markdown/bootstrap-markdown.min.css"/>
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/calendar.css" rel="stylesheet">
    <script type="text/javascript" src="/pages/js/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var productionId = localStorage['productionId'];
            detail(productionId);

            /**
             * 图片上传
             */
            $("#uploadImage").click(function () {
                var formData = new FormData();
                formData.append('upload', $('#imageFile')[0].files[0]);
                $.ajax({
                    url: '/upload/image',
                    type: 'POST',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    if (res.status === 1) {
//                        $("#headerDiv").html('<img src="' + res.data + '">');
                        $("#sbimage").val(JSON.stringify(res.data));
                        alert("上传成功");
                    }
                    else {
                        alert("图片上传失败");
                    }
                }).fail(function (res) {
                    alert("图片上传失败");
                });
            });


            /**
             * sb2文件上传
             */
            $("#uploadSb2").click(function () {
                var formData = new FormData();
                formData.append('upload', $('#sb2File')[0].files[0]);
                $.ajax({
                    url: '/upload/sb2',
                    type: 'POST',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    if (res.status === 1) {
                        $("#sburl").val(JSON.stringify(res.data));
                        alert("上传成功");
                    }
                    else {
                        alert("文件上传失败");
                    }
                }).fail(function (res) {
                    alert("文件上传失败");
                });
            });

            //保存
            $("#productBtn").click(function () {
                var url = "/admin/product/save";
                var showProduct = 0;
                if ($("#showProduct").prop('checked')) {
                    showProduct = 1;
                }
                var id = $("#productId").val(),
                        name = $("#productName").val(),
                        author = $("#author").val(),
                        introduction = $("#introduction").val(),
                        sbimage = $("#sbimage").val(),
                        sburl = $("#sburl").val(),
                        showOrder = $("#showOrder").val();
                $.post(url, {
                    id: id,
                    name: name,
                    author: author,
                    introduction: introduction,
                    sbimage: sbimage,
                    sburl: sburl,
                    showProduct: showProduct,
                    showOrder: showOrder
                }, function (result) {
                    if (result.status === 1) {
                        alert("保存成功！");
                        window.location.href = "/pages/admin/admin_manworks.html";
                    }
                    else {
                        alert("保存失败！"+result.message);
                        window.location.href = "/pages/admin/admin.html";
                    }
                })
            });
        })



        //加载详情
        function detail(productionId) {
            var url = '/admin/product/detail';
            if (productionId.length > 0) {
                $.post(url, {id: productionId}, function (result) {
                    if (result.status === 1) {
                        var data = result.data;
                        $("#productId").val(data.id);
                        $("#productName").val(data.name);
                        $("#author").val(data.author);
                        $("#introduction").val(data.introduction);
                        $("#sbimage").val(data.sbimage);
                        $("#sburl").val(data.sburl);
                        if (data.showProduct===1) {
                            $("#showProduct").prop('checked',true);
                        }

                        $("#showOrder").val(data.showOrder);
                    }
                    else {
                        window.location.href = "/pages/admin/admin_newslist.html";
                    }
                })
            }
        }
    </script>
</head>


<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>所有信息</h5>
                </div>
                <input id="productId" type="text" hidden>
                <div class="ibox-content">
                    <div method="get" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">作品名称</label>
                            <div class="col-sm-10">
                                <input id="productName" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">作者</label>
                            <div class="col-sm-10">
                                <input id="author" type="text" class="form-control">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">作品介绍</label>
                            <div class="col-sm-10">
                                <input id="introduction" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" id="pluscalender">
                            <label class="col-sm-2 control-label">作品图片</label>
                            <div class="col-sm-5">
                                <input id="imageFile" type="file">
                                <input id="sbimage" type="text" hidden>
                            </div>
                            <div>
                                <button id="uploadImage" class="btn">上传</button>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">作品文件</label>
                            <div class="col-md-5">
                                <input id="sb2File" type="file"/>
                                <input id="sburl" type="text" hidden>
                            </div>
                            <div>
                                <button id="uploadSb2" class="btn">上传</button>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否在前台显示</label>
                            <div class="col-sm-10">
                                <input id="showProduct" type="checkbox">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">前台展示顺序</label>
                            <div class="col-sm-10">
                                <input id="showOrder" type="text" class="form-control" placeholder="0">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button id="productBtn" class="btn btn-primary" type="submit" style="margin-top: 50px;">
                                    保存修改
                                </button>
                                <button class="btn btn-white" style="margin-top: 50px;">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>

    <!-- simditor -->
    <script type="text/javascript" src="js/plugins/markdown/markdown.js"></script>
    <script type="text/javascript" src="js/plugins/markdown/to-markdown.js"></script>
    <script type="text/javascript" src="js/plugins/markdown/bootstrap-markdown.js"></script>
    <script type="text/javascript" src="js/plugins/markdown/bootstrap-markdown.zh.js"></script>
    <script src="js/plugins/iCheck/icheck.min.js"></script>
    <script src="js/calendar.min.js"></script>

    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>

</div>
</body>

</html>
